#!usr/bin/perl -w

#定义了Template类
package Template;

require Exporter;
@ISA=qw(Exporter);
@EXPORT=qw(Parse Des WizardPage Process Include Txt);
use strict;

require Description;
require WizardPage;
require Process;
require Include;

sub new()
{
	my $self={};
	bless $self;
	$self->Construct();
	return $self;
}

sub Construct()
{
	my $this=shift;
	$this->{'iDes'}=0;
	$this->{'iWizardPage'}=[];
	$this->{'iProcess'}=[];
	$this->{'iInclude'}=[];
	$this->{'iTxt'}=0;
}

sub Parse()
{
	my $this=shift;
	my ($hashRef)=@_;

	#解析string
	my $txtFile=$hashRef->{'string'};
	$this->ParseTxt($txtFile);

	#解析description
	my $desHashRef=$hashRef->{'description'};
	$this->ParseDes($desHashRef);

	#解析process
	my $processRef=$hashRef->{'process'};
	$this->ParseProcess($processRef);

	#解析include
	my $includeRef=$hashRef->{'include'};
	$this->ParseInclude($includeRef);

	#解析wizardPage
	my $wizardPage=$hashRef->{'wizardpage'};
	$this->ParseWizardPage($wizardPage);
}

sub ParseTxt()
{
	my $this=shift;
	my ($file)=@_;
	open FileHandle,"<$file" or die "cannot open $file\n";
	my (@content)=<FileHandle>;
	close FileHandle;

	my $des;
	foreach (@content)
	{
		$des .= $_;
	}
	$this->Txt($des);
}

sub ParseDes()
{
	my $this=shift;
	my ($hashRef)=@_;
	my $newDes=new Description();
	$newDes->Parse($hashRef);
	$this->Des($newDes);
}

sub ParseProcess()
{
	my $this=shift;
}

sub ParseInclude()
{
	my $this=shift;
	my ($ref)=@_;
	my $newInc=new Include();
	$newInc->Parse($ref);
	$this->Include($newInc);
}

sub ParseWizardPage()
{
	my $this=shift;
	my ($ref)=@_;
	my $newWiardPage=new WizardPage();
	$newWiardPage->Parse($ref);
	$this->WizardPage($newWiardPage);
}

sub Des()
{
	my $this=shift;
	my ($desRef)=@_;
	if (defined $desRef)
	{
		$this->{'iDes'}=$desRef;
	}
	return $this->{'iDes'};
}

sub WizardPage()
{
	my $this=shift;
	my ($wizardPageRef)=@_;
	if (defined $wizardPageRef)
	{
		$this->{'iWizardPage'}=$wizardPageRef;
	}
	return $this->{'iWizardPage'};
}

sub Process()
{
	my $this=shift;
	my ($processRef)=@_;
	if (defined $processRef)
	{
		$this->{'iProcess'}=$processRef;
	}
	return $this->{'iProcess'};
}

sub Include()
{
	my $this=shift;
	my ($includeRef)=@_;
	if (defined $includeRef)
	{
		$this->{'iInclude'}=$includeRef;
	}
	return $this->{'iInclude'};
}

sub Txt()
{
	my $this=shift;
	my ($txt)=@_;
	if (defined $txt)
	{
		$this->{'iTxt'}=$txt;
	}
	return $this->{'iTxt'};
}

1;

